<?php

namespace app\admin\model;

use app\common\model\User as BaseModel;
use app\admin\service\UserService;
class User extends BaseModel
{


    /**
     * 获取器获取recharge_sum充值总额
     */
    public function getRechargeSumAttr($value,$data)
    {
       return $this->recharge()->where('state',1)->sum('pay_amount');
    }

     /**
     * 获取器获取withdraw_total提现总额
     */
    public function getWithdrawTotalAttr($value,$data)
    {
       return $this->withdraw()->where('state',2)->sum('amount');
    }

    /**
     * 搜索器 字段ID
     */
    public function searchIdAttr($query, $value){
        if ($value){
            $query->where('id',$value);
        }
    }
    /**
     * 搜索器 字段name
     */
    public function searchNameAttr($query, $value){
        if ($value){
            $query->where('name','like','%'.$value.'%');
        }
    }

    /**
     * 搜索器 字段phone
     */
    public function searchPhoneAttr($query, $value){
        if ($value) {
            $query->where('phone','like','%'.$value);
        }
    }


    /**
     * 搜索器 字段state
     */
    public function searchStatusAttr($query, $value)
    {
        if ($value!='') {
            $query->where('status', $value);
        }
    }

    /**
     * 搜索器 查询时间范围
     */
    public function searchCreateTimeAttr($query, $value)
    {
        if ($value) {
            $query->whereTime('create_time', 'between', explode(' - ', $value));
        }
    }


}